package com.atguigu.yygh.hosp.controller.api;/*
 * @author: XueYouPeng
 * @time: 2023/6/9 13:59
 */

import com.atguigu.result.Result;
import com.atguigu.utils.HttpRequestHelper;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Department;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@RestController
@Api(tags = "医院管理API接口")
@RequestMapping("/api/hosp")
public class ApiController {

    @Autowired
    HospitalService hospitalService;

    @Autowired
    DepartmentService departmentService;

    @Autowired
    ScheduleService scheduleService;

    /*
     * 上传医院
     * @author: XueYouPeng
     * @time: 2023/6/9 17:02
     */
     @PostMapping("saveHospital")
    public Result saveHospital(HttpServletRequest request){
         Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
         hospitalService.saveHospital(paramMap);
         return Result.ok();
     }

    /*
     * 查询医院
     * @author: XueYouPeng
     * @time: 2023/6/9 19:03
     */
     @PostMapping("hospital/show")
    public Result hospitalShow(HttpServletRequest request){
         Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
         Hospital hospital = hospitalService.show(paramMap);
         return Result.ok(hospital);
     }

     /*
      * 单个上传科室
      * @author: XueYouPeng
      * @time: 2023/6/9 19:15
      */
      @PostMapping("saveDepartment")
      public Result saveDepartment(HttpServletRequest request){
          Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
          departmentService.saveDepartment(paramMap);
          return Result.ok();
      }

      /*
       * 医院端根据hoscode查询该医院自己的科室列表 分页
       * @author: XueYouPeng
       * @time: 2023/6/9 19:34
       */
       @PostMapping("department/list")
       public Result departmentList(HttpServletRequest request){
           Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
           Page<Department> page = departmentService.list(paramMap);
           return Result.ok(page);
       }

       /*
        *
        * @author: XueYouPeng
        * @time: 2023/6/9 19:58
        */
        @PostMapping("department/remove")
        public Result departmentRemove(HttpServletRequest request){
            Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
            departmentService.remove(paramMap);
            return Result.ok();
        }

        /*
         * 单个上传排班
         * @author: XueYouPeng
         * @time: 2023/6/9 20:09
         */
        @PostMapping("saveSchedule")
        public Result saveSchedule(HttpServletRequest request) {
            Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
            scheduleService.saveSchedule(paramMap);
            return Result.ok();
        }

        /*
         * 查询排班列表
         * @author: XueYouPeng
         * @time: 2023/6/9 20:32
         */
         @PostMapping("schedule/list")
         public Result scheduleList(HttpServletRequest request){
             Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
             Page<Schedule> page = scheduleService.list(paramMap);
             return Result.ok(page);
         }

         /*
          * 删除排班
          * @author: XueYouPeng
          * @time: 2023/6/9 20:44
          */
          @PostMapping("schedule/remove")
          public Result scheduleRemove(HttpServletRequest request){
              Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());
              scheduleService.remove(paramMap);
              return Result.ok();
          }
}
